package com.mc.stack;
import java.util.Stack;
public class QueueStack {
	private Stack<Integer> push = new Stack<Integer>();
	private Stack<Integer> pop = new Stack<Integer>();
	private boolean flag = true;
	
	public void offer(int value){
		if(!flag){
			while(!pop.isEmpty())
				push.push(pop.pop());
			flag=true;
		}
		push.push(value);
	}
	public int poll(){
		if(flag){
			while(!push.isEmpty())
				pop.push(push.pop());
			flag=false;
		}
		if(pop.isEmpty())
			return -1;
		return pop.pop();
	}
	public static void main(String[] args) {
		QueueStack qs = new QueueStack();
		qs.offer(2);
		qs.offer(5);
		qs.offer(6);
		qs.offer(7);
		qs.offer(9);
		System.out.println(qs.poll());
		System.out.println(qs.poll());
		System.out.println(qs.poll());
		System.out.println(qs.poll());
		System.out.println(qs.poll());
		System.out.println(qs.poll());
	}
}
